<template>
  <div class="bigScreen">
    <div class="banner">
      <div class="show1">SanTanNew购卡平台</div>
      <div class="show2">简单、快捷、全面的一站式购卡平台</div>
    </div>
    <div class="toolBox">
      <div class="left"></div>
      <div class="paySuccess">恭喜您支付成功!</div>
      <el-button type="success" size="mini" @click="exportExcel()"
        >一键导出</el-button
      >
    </div>
    <el-table :data="list" class="tableClassMain">
      <el-table-column :label="name" prop="apikey"></el-table-column>
      <!-- <el-table-column label="账号" prop="account"></el-table-column>
      <el-table-column label="密码" prop="pwd"></el-table-column>
      <el-table-column label="邮箱密码" prop="emailPwd"></el-table-column> -->
      <el-table-column label="账号类型" prop="type"></el-table-column>
    </el-table>
    <div class="feature" style="margin-top: 1em"></div>
  </div>
</template>

<script>
import ExportJsonExcel from "js-export-excel";
import bigScreen from "@/api/bigScreen";
export default {
  data() {
    return {
      list: [],
      payType: "",
      name: "apikey",
    };
  },
  created() {
    if (this.$route.query.payType == "ajPay"||localStorage.getItem('payType')==='ajPay') {
      this.payType = "ajPay";
      this.name = "脚本激活密钥";
      this.list = [
        {
          apikey: localStorage.getItem("UUIDNEW"),
          type: "脚本激活密钥",
        },
      ];
      this.$confirm("是否导出账号文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.exportExcel();
      });
    } else {
      this.searchList();
    }
  },
  mounted: function () {},
  methods: {
    async searchList() {
      const res = await bigScreen.selectByUUID({
        uuId: localStorage.getItem("UUIDNEW"),
      });
      this.list = res.list;
      if (this.list && this.list.length > 0) {
        this.$confirm("是否导出账号文件?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          this.exportExcel();
        });
      }
    },
    exportExcel() {
      if (this.list.length === 0) {
        this.$message({
          message: "没有需要导出的账号！",
          type: "warning",
        });
        return;
      }
      const dataList = this.list;
      let option = {}; //   option代表的就是excel文件
      let dataTable = []; //   dataTable代表excel文件中的数据内容
      if (dataList) {
        for (let i in dataList) {
          let obj = {
            key: dataList[i].apikey,
            账号类型: dataList[i].type,
          };
          if (this.payType === "ajPay") {
            obj = {
              脚本激活密钥: dataList[i].apikey,
              账号类型: dataList[i].type,
            };
          }
          dataTable.push(obj); //   设置excel每列获取的数据源
        }
      }
      option.fileName = "账号excel"; //excel文件名
      //excel文件数据
      option.datas = [
        {
          //   excel文件的数据源
          sheetData: dataTable,
          //   excel文件sheet的表名
          sheetName: "sheet",
          //   excel文件表头名
          sheetHeader: this.payType === "ajPay"?["脚本激活密钥", "账号类型"]:["key", "账号类型"],
          //   excel文件列名
          sheetFilter: this.payType === "ajPay"?["脚本激活密钥", "账号类型"]:["key", "账号类型"]
        },
      ];
      //   创建ExportJsonExcel实例对象
      let toExcel = new ExportJsonExcel(option);
      //   调用保存方法
      toExcel.saveExcel();
    },
  },
  beforeDestroy() {},
};
</script>

<style lang="scss" scoped>
.bigScreen {
  width: 90%;
  text-align: center;
  padding-top: 0em;
  margin: 0 auto;
  background-color: #f5f7fb !important;
  .banner {
    background-color: #4aac94;
    padding-top: 3em;
    padding-bottom: 3em;
    .show1 {
      margin: 0;
      font-weight: 400;
      color: #fff;
      font-size: 3rem;
    }
    .show2 {
      margin-top: 1.2em;
      margin-bottom: 0;
      font-weight: 400;
      color: #fff;
      font-size: 1.2rem;
    }
    .show3 {
      font-weight: 400;
      margin-top: 0.8em;
      color: #fff;
      font-size: 1.2rem;
      margin-bottom: 0;
    }
  }
  .feature {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-font-smoothing: antialiased;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.42857143;
    color: #333;
    text-align: center;
    box-sizing: border-box;
    margin-top: 1em;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    .feature_item {
      cursor: pointer;
      vertical-align: top;
      display: inline-block;
      width: 22em;
      margin: 1em 1em;
      background-color: #fff;
      padding: 0.5em 2.5em;
      padding-bottom: 2em;
      box-shadow: 0 3px 3px 0 rgb(0 0 0 / 5%);
    }
    .feature_item_2 {
      cursor: pointer;
      vertical-align: top;
      display: inline-block;
      margin: 1em 1em;
      background-color: #fff;
      padding: 0.5em 2.5em;
      padding-bottom: 2em;
      padding-top: 2em;
      box-shadow: 0 3px 3px 0 rgb(0 0 0 / 5%);
      display: flex;
      flex-direction: column;
      justify-content: center;
      margin-top: 25rpx;

      .centerBox {
        display: flex;
        flex-direction: column;
        justify-content: center;
        margin-top: 25px;

        #qrCode {
          text-align: center;
          display: flex;
          align-items: center;
          justify-content: center;
        }

        .tip {
          text-align: center;
          margin-top: 30px;
          font-size: 1rem;
        }

        .tipRed {
          text-align: center;
          margin-top: 10px;
          color: red;
          font-size: 1rem;
        }
      }

      .page-title {
        display: inline-block;
        position: relative;
        padding-right: 25px;
        padding-bottom: 15px;
        color: #a788e7;
        font-size: 1.4em;
        text-align: left;
      }
      .page-title-wx {
        display: inline-block;
        position: relative;
        padding-right: 25px;
        padding-bottom: 15px;
        color: #67c23a;
        font-size: 1.4em;
        text-align: left;
      }
      .page-item {
        font-size: 1em;
        color: grey;
        text-align: left;
      }
    }
    .item_iconfont_1 {
      width: 10rem;
      height: 10rem;
      margin-top: 1.5em;
    }

    .item_iconfont_2 {
      width: 3rem;
      height: 3rem;
      margin-top: 1.5em;
    }
    .item_iconfont_3 {
      width: 3rem;
      height: 3rem;
    }
    .item_iconfont {
      width: 5rem;
      height: 5rem;
      margin-top: 1.5em;
    }
    .title {
      margin-top: 0.6em;
      margin-bottom: 0.6em;
      font-size: 2.5rem;
      width: 100%;
    }
    .feature_item .content {
      line-height: 200%;
      font-size: 1rem;
      color: #444;
    }
  }
  a {
    color: #4aac94;
    text-decoration: none;
  }
}
h2 {
  display: block;
  font-size: 1.5em;
  margin-block-start: 0.83em;
  margin-block-end: 0.83em;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
  font-weight: bold;
}
.titleSpecial {
  margin-top: 1.6em;
  margin-bottom: 0.6em;
  font-size: 2.5rem;
  width: 100%;
}
.ddje {
  width: 100%;
  text-align: left;
  color: red;
}
.payBox {
  justify-content: center;
  display: flex;
  align-items: center;
  button {
    display: flex;
    align-items: center;
  }
}
.paySuccess {
  color: red;
  font-size: 2rem;
  margin-top: 1rem;
  margin-bottom: 1rem;
}
.toolBox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left {
    width: 6rem;
    height: 3rem;
  }
  button {
    width: 6rem;
    height: 3rem;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}

.tableClassMain {
  box-shadow: 0px 3px 6px 1px rgba(0, 0, 0, 0.16);
  border-radius: 20px 20px 20px 20px;
}
</style>